temp-bikes/04 Aggregate predictions/aggregate-predictions.R

############################################################
### Aggregate prediction                                 ###
############################################################
library(data.table)
library(ggplot2)
library(devtools)
load_all()

# State of the world including variables for precise match #############
sotw_cont <- subset(bikes_d_log, select = c(t, temp, hum, windspeed))
matchi <- data.frame(t = 1:730, family_day = 0)
matchi[c(327, 357:358, 691, 723:724), 2] <- 1

# Generate agg preds including baseline ################################
df_agg <- gen_atomic_df()
df_base <- gen_baseline(bikes_atom, 401)
df_agg <- rbind(df_agg, df_base)

weights <- caliper_relevance_new(
    bikes_atom,
    sotw_cont,
    670,
    cw = 1,
    matching_vars = NULL #matchi
)

RAL_data <- RAL_calculator(weights, bikes_atom)
df_cal_prop <- gen_RAA(RAL_data, "propto", "caliper")
df_agg <- rbind(df_agg, df_cal_prop)

# Vis ##################################################################
plt <- ggplot(df_agg[t > 670], aes(x = t, y = lpdens, col = method)) +
    geom_line()
ggsave("temp-bikes/agents/lpdens_all_no_match.pdf", plot = plt)

# saving data for fata
df_match <- df_agg

df_agg[, .(predabil = sum(lpdens)), by = .(method)]
df_match[, .(predabil = sum(lpdens)), by = .(method)]
ooelrich/oscbvar documentation built on Sept. 8, 2021, 3:31 p.m.